package com.library.controller;

import com.library.pojo.dto.book.BookPageQueryDTO;
import com.library.result.PageResult;
import com.library.result.Result;
import com.library.service.BookService;
import com.library.service.impl.BookServiceImpl;

/**
 * 用户对图书操作
 * 只写对外的方法
 */
public class BookController {

    BookService bookService = new BookServiceImpl();

    /**
     * 查询图书列表
     * @param bookPageQueryDTO 分页参数（必填：pageNum/pageSize；可选：bookId/name/author/publisher/state关键词）
     * @return PageResult<LibraryBooks>：分页图书列表
     */
    public Result<PageResult> pageQuery(BookPageQueryDTO bookPageQueryDTO) {
        PageResult pageResult =bookService.pageQuery(bookPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 根据图书编号借阅图书
     * @param bookId 图书Id
     * @return Result<String>：成功/失败提示
     */
    public Result<String> borrowBook(int bookId, Integer userId){
        int flag = bookService.borrowBook(bookId, userId);
        if(flag == 1) {
            return Result.success("借阅成功");
        }
        return Result.error("借阅失败");
    }
}
